<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>我的账号</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no,email=no,address=no" />
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <link rel="stylesheet" href="../css/common.css" />
    <link rel="stylesheet" href="../css/y_index.css" />
</head>

<body>
    <div class="">
        <form action="" enctype="multipart/form-data" method="post" name="form" id="form" onsubmit="return formSubmit()">
            <label class="flex_sb plr30 ptb30 bw">
                <input type="file" name="headimg" hidden id="hd_img" onchange="localImg(this)" />
                <span class="col3 font15">编辑头像</span>
                <em class="flex_a">
                    <img class="mr20 hd_img" src="../img/center.png" id="headimg"/>
                    <img src="../img/y_arrow_right.png" class="arrow_r"/>
                </em>
            </label>
        </form>
        <div class="flex_sb plr30 font15 mt20 bw bdb" id="nickname">
            <span class="col3">名字</span><em class="flex_a"><input type="text" placeholder="请输入用户名" class="ml20 nickname font15 col9 h100 flex1 tae"></em>
        </div>
        <div class="flex_sb ptb30 plr30 font15  bw bdb" id="phone">
            <span class="col3">账号</span><em class="flex_a"><i class="col9  phone">15812874182</i></em>
        </div>
        <a href="./ser_password.html" class="flex_sb ptb30 plr30 font15 bw bdb">
        <span class="col3">修改密码</span><em class="flex_a"><img src="../img/y_arrow_right.png" class="arrow_r"/></em>
    </a>
        <a href="./ser_address.html" class="flex_sb ptb30 plr30 font15 bw">
        <span class="col3">地址管理</span><em class="flex_a"><img src="../img/y_arrow_right.png" class="arrow_r"/></em>
    </a>
        <div class="main_btn tap" style="margin-top: .6rem">保存</div>
    </div>
</body>

</html>
<script type="text/javascript" src="../js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="../js/dlc.js"></script>
<script type="text/javascript" src="../js/jquery.form.js"></script>
<script>
var localImg;
dlctipbox.loading('载入中...');
dlc_request('/App/Vip/api', { api_name: 'vip_info' }, function(res) {
    dlctipbox.clear();
    if (res.code == 1) {
        $('#headimg').attr('src', res.data.headimg);
        $('.nickname').text(res.data.nickname);
    } else {
        console.log(res);
    }
});

$('#hd_img').on('change', function() {
    $('#form').submit();
});

//保存
$('.main_btn tap').click(function() {
    var nickname = $('.nickname').val();
    if (isNull(nickname)) {
        dlctipbox.show('请输入用户名');
    } else {

    }
});

function formSubmit() {
    $('#form').ajaxSubmit({
        type: 'POST',
        data: { api_name: 'update_himg' },
        url: dlcUrl() + '/App/Vip/api',
        dataType: 'json',
        beforeSubmit: function() {
            var imgValue = $('#hd_img').val();
            if (imgValue == '') {
                dlctipbox.show('请选择图片');
                return false;
            }
            dlctipbox.loading('上传中...');
        },
        success: function(res) {
            dlctipbox.clear();
            if (res.code == 1) {
                dlctipbox.show('修改成功');
                $('#headimg').attr('src', localImg);
            } else {
                dlctipbox.show(res.msg);
            }
        },
        error: function(err) {
            console.log(err);
        }
    });
    return false; //阻止表单默认提交
}

function localImg(that) {
    console.log(getObjectURL(that.files[0]));
    localImg = getObjectURL(that.files[0]);
}
</script>